<%--
  - Author		:	이 영호(Youngho Lee)	
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8" %>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />

		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript">
			$(function(){
			});
			
			function validation(){
				try{
					with(document.frm){
						//bizNum.value=bizNum1.value+"-"+bizNum2.value+"-"+bizNum3.value;
						tel.value=tel1.value+"-"+tel2.value+"-"+tel3.value;
						mobile.value=mobile1.value+"-"+mobile2.value+"-"+mobile3.value;
						fax.value=fax1.value+"-"+fax2.value+"-"+fax3.value;
						addrNum.value=addrNum1.value+"-"+addrNum2.value;
						
						for(var i=0;i<$("input").length;i++){
							if($("input").eq(i).attr("name") && $("input").eq(i).val().replace(/\s/g, '') == ""){
								alert($("input").eq(i).attr("title")+"을(를) 입력 해주세요.");
								$("input").eq(i).focus();
								return false;
							}
						}
						
						if(pw.value != pwChk.value){
							alert("비밀번호와 비밀번호 확인의 같지 않습니다.");
							return false;
						}
					}
				}catch(err){
					alert(err);
					return false;	
				}
				
				if(! confirm("수정하시겠습니까?")){
					return false;
				}else{
					$.ajax({
						type : 'post',
						async : true,
						url : '<c:url value="/mypage/updateUser.do" />',
						dataType : 'json',
						timeout : 30000,
						cache : false,
						data : $("#frm").serialize(),
						contentType : 'application/x-www-form-urlencoded; charset=UTF-8',
						error : function(data, status, err) {
							alert("요청 처리 중 에러가 발생하였습니다.\n\nerror code : "+ err);
							return false;
						},
						success : function(data){
							$.each(data, function(key, val) {
								if (key == 'SUCCESS' && val == true){
									alert("수정이 완료되었습니다.");
									location.reload();
									return false;
								}
								if (key == 'SUCCESS' && val == false){
									alert("처리 중 에러가 발생하였습니다.");
									return false;
								}
							});
						},
						beforeSend : function(){
						},
						complete : function(){
						}
					});
				}
				
				//return true;
			}
			
			function addrPop(){
				window.open("<c:url value="/addr.jsp" />");
			}
			
			function setAddr(addrNum, addr1){
				document.frm.addrNum1.value = addrNum.split("-")[0]; 
				document.frm.addrNum2.value = addrNum.split("-")[1];
				document.frm.addr1.value = addr1;
			}
			
			function fn_reset(){
				document.frm.reset();
				alert("취소되었습니다.");
			}

		</script>
	</head>
	<body>
<%@ include file="/WEB-INF/pages/includes/header.jsp" %>
		<div class="bodyWrap">
<%@ include file="/WEB-INF/pages/includes/left.jsp" %>
			<div class="contWrap">
				<div class="contMenuTitle">
					<img src="<c:url value="${dirImages}/subtit_01_2.gif" />" title="회원 정보 수정" alt="회원 정보 수정">
				</div>
				<form id="frm" name="frm" method="post" action="<c:url value="/mypage/updateUser.do" />">
					<table class="formTbl">
						<caption style="color: #c9c9c9; font-size: 12px;"><font class="redFont">*</font>표시는 필수입력 사항</caption>
						<tbody>
							<tr>
								<th><font class="redFont">*</font> 아이디</th>
								<td colspan="3">
									<input type="hidden" name="idx" value="${user.idx}">
									<c:out value="${user.id}" />
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> 사업자 등록 번호</th>
								<td colspan="3">
									<%--
										<input type="text" name="bizNum1" title="사업자 등록 번호" alt="사업자 등록 번호" value="<c:out value="${fn:split(user.bizNum, '-')[0]}" />">-<input type="text" name="bizNum2" title="사업자 등록 번호" alt="사업자 등록 번호" value="<c:out value="${fn:split(user.bizNum, '-')[1]}" />">-<input type="text" name="bizNum3" title="사업자 등록 번호" alt="사업자 등록 번호" value="<c:out value="${fn:split(user.bizNum, '-')[2]}" />">
									 --%>
									 ${user.bizNum}
									<input type="hidden" name="bizNum" title="사업자 등록 번호" alt="사업자 등록 번호" value="${user.bizNum}">
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> 이름</th>
								<td colspan="3">
									<input type="text" name="name" title="이름" alt="이름" value="<c:out value="${user.name}" />">
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> 비밀번호</th>
								<td>
									<input type="password" name="pw" title="비밀번호" alt="비밀번호" value="<c:out value="${user.pw}" />">
								</td>
								<th><font class="redFont">*</font> 비밀번호 확인</th>
								<td>
									<input type="password" name="pwChk" title="비밀번호 확인" alt="비밀번호 확인" value="<c:out value="${user.pw}" />">
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> 이메일</th>
								<td colspan="3">
									<input type="text" name="email" title="이메일" alt="이메일" value="<c:out value="${user.email}" />">
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> 업체명</th>
								<td colspan="3">
									<input type="text" name="bizNm" title="업체명" alt="업체명" value="<c:out value="${user.bizNm}" />">
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> 부서명</th>
								<td colspan="3">
									<input type="text" name="team" title="부서명" alt="부서명" value="<c:out value="${user.team}" />">
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> 회원등급</th>
								<td colspan="3">
									<c:choose>
										<c:when test="${user.authority eq 'ROLE_USER'}">일반회원</c:when>
										<c:when test="${user.authority eq 'ROLE_TESTER'}">체험단</c:when>
										<c:otherwise>user.authority</c:otherwise>
									</c:choose>
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> 전화번호</th>
								<td colspan="3">
									<input type="text" name="tel1" title="전화번호" alt="전화번호" value="<c:out value="${fn:split(user.tel, '-')[0]}" />">-<input type="text" name="tel2" title="전화번호" alt="전화번호" value="<c:out value="${fn:split(user.tel, '-')[1]}" />">-<input type="text" name="tel3" title="전화번호" alt="전화번호" value="<c:out value="${fn:split(user.tel, '-')[2]}" />">
									<input type="hidden" name="tel" title="전화번호" alt="전화번호" value="${user.tel}">
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> 휴대전화</th>
								<td colspan="3">
									<input type="text" name="mobile1" title="휴대전화" alt="휴대전화" value="<c:out value="${fn:split(user.mobile, '-')[0]}" />">-<input type="text" name="mobile2" title="휴대전화" alt="휴대전화" value="<c:out value="${fn:split(user.mobile, '-')[1]}" />">-<input type="text" name="mobile3" title="휴대전화" alt="휴대전화" value="<c:out value="${fn:split(user.mobile, '-')[2]}" />">
									<input type="hidden" name="mobile" title="휴대전화" alt="휴대전화" value="${user.mobile}">
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> FAX</th>
								<td colspan="3">
									<input type="text" name="fax1" title="FAX" alt="FAX" value="<c:out value="${fn:split(user.fax, '-')[0]}" />">-<input type="text" name="fax2" title="FAX" alt="FAX" value="<c:out value="${fn:split(user.fax, '-')[1]}" />">-<input type="text" name="fax3" title="FAX" alt="FAX" value="<c:out value="${fn:split(user.fax, '-')[2]}" />">
									<input type="hidden" name="fax" title="FAX" alt="FAX" value="${user.fax}">
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> 우편번호</th>
								<td colspan="3">
									<input type="text" name="addrNum1" title="우편번호" alt="우편번호" maxlength="3" size="3" readonly="readonly" onfocus="javascript:this.blur();" value="<c:out value="${fn:split(user.addrNum, '-')[0]}" />">
									-
									<input type="text" name="addrNum2" title="우편번호" alt="우편번호" maxlength="3" size="3" readonly="readonly" onfocus="javascript:this.blur();" value="<c:out value="${fn:split(user.addrNum, '-')[1]}" />">
									<input type="hidden" name="addrNum" title="우편번호" alt="우편번호" value="${user.addrNum}">
									<img class="btn" src="<c:url value="${dirImages}/join_add_check.gif" />" title="우편번호 확인" alt="우편번호 확인" style="vertical-align: top;" onclick="javascript:addrPop();" />
								</td>
							</tr>
							<tr>
								<th><font class="redFont">*</font> 주소1</th>
								<td colspan="3">
									<input type="text" name="addr1" title="주소1" alt="주소1" maxlength="80" size="80" value="<c:out value="${user.addr1}" />">
								</td>
							</tr>
							<tr>
								<th>주소2</th>
								<td colspan="3">
									<input type="text" name="addr2" title="주소2" alt="주소2" maxlength="80" size="80" value="<c:out value="${user.addr2}" />">
								</td>
							</tr>
						</tbody>
					</table>
					<div class="btnWrap centerBtnWrap">
						<input type="button" class="btn btn_ok" alt="확인" title="확인" value="" onclick="return validation();">
						<input type="button" class="btn btn_cancel" alt="취소" title="취소" value="" onclick="javascript:fn_reset();">
					</div>
				</form>
			</div>
		</div>
<%@ include file="/WEB-INF/pages/includes/footer.jsp" %>
	</body>
</html> 